<?php
/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
include( '../global/initialize.php' );

aos_header( 'News' );

$query = "SELECT * FROM news WHERE ruler_id = " . $_SESSION[ 'ruler_id' ] . " AND seen = 0 ORDER BY turn DESC" ;
$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
$num = mysql_numrows( $result );
?>
					<div class="blok">
						<?php transprint( "Category" ); ?>:<br />
<?php
print translate( "Unread" ) . " <a href=\"news_list.php?type=0\">" . translate( 'Operations' ) . "</a> <a href=\"news_list.php?type=1\">" . translate( 'Military' ) . "</a> <a href=\"news_list.php?type=2\">" . translate( 'Civilian' ) . "</a><br/>\r\n";
?>
					</div>
					<br />
<?php
if( $num > 0 ) {
    print "<form method=\"post\" action=\"news_action.php?type=unread\">\r\n";
    print "<table><th colspan=\"4\">" . translate( 'Unread news' ) . ":</th>\r\n";
    print "<tr><td>" . translate( 'Select' ) . "</td><td>" . translate( 'Type' ) . "</td><td>" . translate( 'Subject' ) . "</td><td>" . translate( 'Date' ) . "</td></tr>\r\n";
    $i = 0;
    while ( $i < $num ) {
        if( $i % 2 == 0 ) {
            print "<tr id=\"even\">";
        }
        else {
            print "<tr>";
        }
        $type = "";
        if( mysql_result( $result, $i, "type" ) == 0 ) {
        	$type = "Operations";
        }
        else if( mysql_result( $result, $i, "type" ) == 1 ) {
        	$type = "Military";
        }
        else if( mysql_result( $result, $i, "type" ) == 2 ) {
        	$type = "Civilian";
        }
        
        print "<td><input type=\"checkbox\" name=\"$i\" id=\"checkbox$i\" /></td><td>" . translate( $type ) . "</td><td><a href=\"news_item.php?id=" .  mysql_result( $result, $i, "news_id" ) . "\"><strong>" . mysql_result( $result, $i, "subject" ) . "</strong></a></td><td>" .  mysql_result( $result, $i, "date" );
        print "</td></tr>\r\n";
        $i ++;
    }
    print( "</table>\r\n" );
    print "<a href=\"javascript:void();\" onclick=\"setSelect(true);\">" . translate( 'select all' ) . "</a> ";
    print "<a href=\"javascript:void();\" onclick=\"setSelect(false);\">" . translate( 'select none' ) . "</a> ";
    print "<input type=\"submit\" value=\"" . translate( 'mark read' ) . "\" name=\"read\" /> ";
    print "<input type=\"submit\" value=\"" . translate( 'delete' ) . "\" name=\"delete\" /></form>";
}
else {
	print( "<div class=\"blok\">\r\n" );
	print( translate( "You have no unread news items." ) . "<br />\r\n" );
	print( "</div>\r\n" );    
}
?>
					<script language="JavaScript" type="text/javascript">
						function setSelect( toggle ) {
							var still = true;
							var i = 0;
							while ( still ) {
								var tmp = document.getElementById( "checkbox" + i );
								if( !tmp ) {
									still = false;
								}
								else {
									tmp.checked = toggle;
								}
								i ++;
							}
						}
					</script>
<?php
aos_footer();
?>
